<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>editer</title>
    <script>
        YMWL_ROOT_URL = '{:request()->root()}';
    </script>
    <script type="text/javascript" src="__libs__/jquery/jquery.min.js?v=__lkversion__"></script>
    <link href="__libs__/amaze/css/amazeui.min.css?v=__lkversion__" type="text/css" rel="stylesheet" />
    <script src="__libs__/amaze/js/amazeui.min.js?v=__lkversion__" type="text/javascript"></script>
    <script src="__libs__/layer/layer.js?v=__lkversion__" type="text/javascript"></script>
    <script src="__libs__/layui/layui.js?v=__lkversion__" type="text/javascript"></script>
    <link href="__libs__/layui/css/layui.css?v=__lkversion__" rel="stylesheet">
    <link rel="stylesheet" href="__libs__/myeditor/css/editormd.css?v=__lkversion__"/>
    <script src='__libs__/myeditor/editormd.js'></script>
    <script src="__libs__/myeditor/lib/marked.min.js?v=__lkversion__"></script>
    <script src="__libs__/myeditor/lib/prettify.min.js?v=__lkversion__"></script>
    <script src="__libs__/myeditor/lib/raphael.min.js?v=__lkversion__"></script>
    <script src="__libs__/myeditor/lib/underscore.min.js?v=__lkversion__"></script>
    <script src="__libs__/myeditor/lib/sequence-diagram.min.js?v=__lkversion__"></script>
    <script src="__libs__/myeditor/lib/flowchart.min.js?v=__lkversion__"></script>
</head>

<style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }
    #question {
        font-size: 13px;
        color: #555555;
        border: 1px solid #e5e3e9;
        border-radius: 8px;
    }
    button.keep {
        width: 66px;
        height: 36px;
        color: #ffffff;
        font-size: 13px;
        background-color: #7571f9;
        border-radius: 16px;
    }
    button.reset {
        width: 66px;
        height: 36px;
        color: #555555;
        font-size: 13px;
        background-color: #f7f7f7;
        border-radius: 16px;
        border: 0;
    }
</style>
<body>
<div style="width: 90%;height: 100%;margin:5px auto;">
    <p style="font-size: 13px;width: 100%;margin-top: 24px;margin-bottom: 8px;color:#999999">常见问题：</p>
    <input type="text" id="question" class="layui-input" value="{$question}">

    <p style="font-size: 13px;width: 100%;margin-top: 24px;margin-bottom: 8px;color:#999999">关键词(最多6个字)：</p>
    <input type="text" id="keyword" class="layui-input" value="{$keyword}">

    <p style="font-size: 13px;width: 100%;margin-top: 24px;margin-bottom: 8px;color:#999999">排序字段(数字越大,越靠前)：</p>
    <input type="text" id="sort" class="layui-input" value="{$sort}">

    <p style="font-size: 13px;width: 100%;margin-top: 24px;margin-bottom: 8px;color:#999999">是否显示（客户端是否展示）：</p>
    <select name="status"  id="status" style="padding: 3px 10px;font-size: 14px;border-radius: 15px;border: 1px solid #e5e3e9;height: 32px;">
        <option value="1" {if $status == 1} selected{/if}>显示</option>
        <option value="0" {if $status == 0} selected{/if}>不显示</option>
    </select>

    <p style="font-size: 13px;width: 100%;margin-top: 20px;margin-bottom: 8px;color:#999999">解决回答：</p>
    <div id="a-editormd" style="width: 100%;height:100px;margin :0px;padding: 0px;">
        <textarea class="editormd-markdown-textarea" name="test-editormd-markdown-doc"
                  id="a_editormd">{$answer}</textarea>
        <textarea class="editormd-html-textarea" name="editorhtml" id="a_editorhtml"></textarea>
    </div>
    <div class="layui-form-item" style="margin-top: 24px;text-align: center">
        <button class="layui-btn keep" onclick="geton()" lay-submit lay-filter=" template">保存</button>
        <button type="reset" onclick="reset()" class="layui-btn layui-btn-primary reset">取消</button>
    </div>
</div>
</body>
<script>

    $(function () {

        testEditor = editormd("a-editormd", {
            width: "100%",
            height: 260,
            path: '__libs__/myeditor/lib/',
            codeFold: true,
            //syncScrolling : false,
            saveHTMLToTextarea: true,    // 保存 HTML 到 Textarea
            searchReplace: true,
            watch: true,                // 关闭实时预览
            htmlDecode: "style,script,iframe|on*",            // 开启 HTML 标签解析，为了安全性，默认不开启    
            //toolbar  : false,             //关闭工具栏
            //previewCodeHighlight : false, // 关闭预览 HTML 的代码块高亮，默认开启
            emoji: true,
            taskList: true,
            tocm: true,         // Using [TOCM]
            tex: true,                   // 开启科学公式TeX语言支持，默认关闭
            flowChart: true,             // 开启流程图支持，默认关闭
            sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
            //dialogLockScreen : false,   // 设置弹出层对话框不锁屏，全局通用，默认为true
            //dialogShowMask : false,     // 设置弹出层对话框显示透明遮罩层，全局通用，默认为true
            //dialogDraggable : false,    // 设置弹出层对话框不可拖动，全局通用，默认为true
            //dialogMaskOpacity : 0.4,    // 设置透明遮罩层的透明度，全局通用，默认值为0.1
            //dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色，全局通用，默认为#fff
            imageUpload: true,
            imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
            imageUploadURL: YMWL_ROOT_URL + "/admin/event/uploadimg",
            onload: function () {
                $('#question').blur();
                $('textarea').blur();
                // console.log('onload', this);
                // this.fullscreen();
                // this.unwatch();
                // this.watch().fullscreen();
                // this.setMarkdown("#PHP");
                // this.width("100%");
                // this.height(480);
                // this.resize("100%", 640);
            }

        }
        );
    });


    var lock = false;

    function geton() {
        var q = $("#question").val();
        var k = $("#keyword").val();
        var a = $("#a_editorhtml").val();
        var ra = $("#a_editormd").val();
        var sort = $("#sort").val();
        var status = $("#status").val();
        var qid = {$qid};
        a = a.replace(/><img/g, ' target="_blank"><img');
        if (q && a) {
            if (!lock) {
                lock = true;
                $.ajax({
                    url: YMWL_ROOT_URL + '/admin/manager/addquestion',
                    type: 'post',
                    data: {question: q,keyword:k, answer: a, answer_read: ra, qid: qid,sort:sort,status:status},
                    success: function (res) {

                        if (res.code == 0) {
                            layer.msg(res.msg, {
                                icon: 1, end: function () {
                                    parent.location.reload();
                                }
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2
                            });
                        }
                        lock = false;
                    }
                });
            }
        } else {
            layer.msg('数据不完整');
        }
    }

    function reset(){
        parent.layer.closeAll();
    }

</script>
</html>